package training_camp.day4.leetcode0207;

public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA==null ||headB==null) return null;
        ListNode currA = headA;
        ListNode currB = headB;
        boolean flagA = false;
        boolean flagB = false;
        while (currA != currB) {
            if (currA.next == null && !flagA) {
                currA = headB;
                flagA = true;
            } else {
                currA = currA.next;
            }
            if (currB.next == null && !flagB) {
                currB = headA;
                flagB = true;
            } else {
                currB = currB.next;
            }
        }
        return currA;
    }
}